home *** CD-ROM | disk | FTP | other *** search
- /*
- * Auxiliary.cpp
- *
- * Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com
- *
- * This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
- *
- * FlasKMPEG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * FlasKMPEG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
- #include <windows.h>
- #include <commctrl.h>
- #include "auxiliary.h"
- #include "resource.h"
- #include "stdio.h"
- #include <math.h>
-
-
-
- int GetOutputFileName(HWND hWnd, char* fileName,char* Dir, char* Title){
- OPENFILENAME oifn;
- // Initialize OPENFILENAME
- ZeroMemory(&oifn, sizeof(OPENFILENAME));
- oifn.lStructSize = sizeof(OPENFILENAME);
- oifn.hwndOwner = hWnd;
- oifn.lpstrFile = fileName;
- oifn.nMaxFile = 1024;
- oifn.lpstrFilter = "";
- oifn.nFilterIndex = 1;
- oifn.lpstrFileTitle = NULL;
- oifn.lpstrTitle = Title;
- oifn.nMaxFileTitle = 0;
- oifn.lpstrInitialDir = Dir;
- oifn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
- if(!GetSaveFileName(&oifn))
- return 0;
- return 1;
- }
-
- HWND CreateNormalWindow(WNDPROC WndProc, HINSTANCE hInstance, HWND hParent){
-
- return CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DISPLAY), hParent, (DLGPROC)WndProc);
-
-
- }
-
- void WindowShow(HWND hWnd){
- ShowWindow(hWnd, SW_SHOW);
- }
- void WindowHide(HWND hWnd){
- ShowWindow(hWnd, SW_HIDE);
- }
-
- void WindowResize(HWND window, int w, int h){
- RECT rc;
- GetWindowRect(window, &rc);
- MoveWindow(window, rc.left, rc.top, w, h , TRUE);
- }
-
- void WindowClientResize(HWND window, int w, int h){
- RECT rc;
- SetRect(&rc, 0, 0, w, h);
- AdjustWindowRect(&rc,GetWindowLong(window,GWL_STYLE),FALSE);
- WindowResize(window, rc.right-rc.left, rc.bottom - rc.top);
-
- }
-
- void WindowMove(HWND window, int x, int y){
- RECT rc;
- GetWindowRect(window, &rc);
- MoveWindow(window, x, y, rc.right-rc.left, rc.bottom-rc.top, TRUE);
- }
- void SetText(HWND hWnd, char *text){
- if(text==NULL)
- return;
- SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)text);
- }
- void MenuSetText(HMENU hMenu,int item ,char *text ){
- MENUITEMINFO item_info;
- int kk;
- if(text==NULL)
- return;
-
- item_info.cbSize = sizeof(item_info);
- // item_info.fMask = MIIM_DATA|MIIM_ID|MIIM_STATE|MIIM_SUBMENU|MIIM_TYPE;
- // GetMenuItemInfo( hMenu, item, TRUE, &item_info);
-
- item_info.fMask = MIIM_TYPE;
- item_info.fType = MFT_STRING;
- item_info.dwTypeData = text;
- SetMenuItemInfo( hMenu, item, TRUE, &item_info);
-
- }
-
- void MenuAddItem(HMENU hMenu,int item , int wID,char *text){
- MENUITEMINFO item_info;
- int kk;
- if(text==NULL)
- return;
-
- item_info.cbSize = sizeof(item_info);
-
- item_info.fMask = MIIM_TYPE|MIIM_ID;
- item_info.fType = MFT_STRING;
- item_info.dwTypeData = text;
- item_info.wID = wID;
- InsertMenuItem( hMenu, item, TRUE, &item_info);
- }
- HMENU MenuGetPopup( HMENU hMenu, int item ){
- MENUITEMINFO item_info;
- int kk;
- item_info.cbSize = sizeof(item_info);
- item_info.fMask = MIIM_SUBMENU;
- GetMenuItemInfo( hMenu, item, TRUE, &item_info);
- return item_info.hSubMenu;
-
- }
- void MenuCheck(HWND hWnd, int item)
- {
- CheckMenuItem(GetMenu(hWnd),item, MF_CHECKED);
- }
- void MenuUnCheck(HWND hWnd, int item)
- {
- CheckMenuItem(GetMenu(hWnd),item, MF_UNCHECKED);
-
- }
- void MenuEnable(HWND hWnd, int item)
- {
- EnableMenuItem(GetMenu(hWnd), item, MF_ENABLED);
- }
- void MenuDisable(HWND hWnd, int item)
- {
- EnableMenuItem(GetMenu(hWnd), item, MF_GRAYED);
- }
- void MenuSetText(HWND hWnd, int item){
-
- }
- void TabSetText(HWND hTab, int item, char *text){
- TCITEM props;
-
- if(text==NULL)
- return;
-
- props.mask = TCIF_TEXT;
- props.pszText = text;
- SendMessage( hTab, TCM_SETITEM, (WPARAM) item, (LPARAM)&props);
-
- }
- void DlgSetFocus(HWND hDlg, int control){
- SetFocus(GetDlgItem(hDlg, control));
- }
-
- void DlgCheck(HWND hDlg, int item){
-
- SendDlgItemMessage( hDlg, item, BM_SETCHECK, BST_CHECKED ,0);
- }
-
- void DlgUnCheck(HWND hDlg, int item){
- SendDlgItemMessage( hDlg, item, BM_SETCHECK, BST_UNCHECKED ,0);
- }
-
- bool DlgIsChecked(HWND hDlg, int item){
- return (SendDlgItemMessage( hDlg, item, BM_GETCHECK, 0, 0)==BST_CHECKED);
- }
-
- void DlgEnable(HWND hDlg, int item){
- EnableWindow( GetDlgItem(hDlg, item), true);
- }
- void DlgDisable(HWND hDlg, int item){
- EnableWindow( GetDlgItem(hDlg, item), false);
- }
-
- char *DlgGetText( HWND hDlg, int item, char* text){
- if(text==NULL)
- return NULL;
-
- GetDlgItemText( hDlg, item, text, 1024);
- return text;
- }
- int DlgGetText( HWND hDlg, int item){
- char szTemp[1024];
- GetDlgItemText( hDlg, item, szTemp, 1024);
- return atoi(szTemp);
- }
- void DlgSetText(HWND hDlg, int item, int number){
-
- char szTemp[1024];
- SetDlgItemText(hDlg, item, itoa(number, szTemp, 10));
- }
- void DlgSetDouble(HWND hDlg, int item, double number){
- char szTemp[1024];
- sprintf(szTemp, "%.2f", number);
- SetDlgItemText(hDlg, item, szTemp);
- }
-
- void DlgSetText(HWND hDlg, int item, char* text){
- if(text==NULL)
- return;
-
- SetDlgItemText(hDlg, item, text);
- }
-
- int DlgGetInt(HWND hDlg, int item){
- char szTemp[1024];
- GetDlgItemText( hDlg, item, szTemp, 1024);
- return atoi(szTemp);
- }
-
- void DlgCheckBoxState(HWND hDlg, int item, int state)
- {
- if(state)
- DlgCheck(hDlg, item);
- else
- DlgUnCheck(hDlg, item);
- }
- // LIST BOXES
- void ListAddText(HWND list, char *text){
- SendMessage(list, CB_ADDSTRING, 0, (LPARAM) text);
- }
- int ListGetCur(HWND list){
- return SendMessage(list, CB_GETCURSEL, 0,0);
- }
- void ListSetCur(HWND list, int cur){
- SendMessage(list, CB_SETCURSEL, cur, 0);
- }
- void MillisecondsToTime( char *str, DWORD time)
- {
-
- //Me pasan el tiempo que tengo que formatear en milisegundos
- int segundos, minutos, horas;
- if(str==NULL) return;
- segundos= floor(time/1000);
- segundos=segundos%60;
- minutos= floor(time/60000);
- minutos= minutos%60;
- horas= floor((double)time/3600000);
- if (minutos <=9)
- if (segundos<=9)
- sprintf( str, "%d:0%d:0%d", horas, minutos, segundos);
- else
- sprintf( str, "%d:0%d:%d", horas, minutos, segundos);
- else
- if (segundos<=9)
- sprintf( str, "%d:%d:0%d", horas, minutos, segundos);
- else
- sprintf( str, "%d:%d:%d", horas, minutos, segundos);
-
- return;
- }
-
- StringFrameRate(int fr, char *sFrameRate)
- {
- int frameRate;
- switch( fr )
- {
- case 23976://24000/1001
- strcpy(sFrameRate, "FILM at 23.976 fps");
- break;
- case 24:
- frameRate=24;
- strcpy(sFrameRate, "FILM at 24 fps");
- break;
- case 25:
- frameRate=25;
- strcpy(sFrameRate, "PAL at 25 fps");
- break;
- case 2997:
- frameRate=(double)30000/(double)1001;
- strcpy(sFrameRate, "NTSC at 29.97 fps");
- break;
- case 30:
- frameRate=30;
- strcpy(sFrameRate, "NTSC at 30 fps");
- break;
- default:
- strcpy(sFrameRate, "unknown");
- frameRate=25;
- }
- }
-